﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{

    public abstract class BaseSingletonInstance<T> : IDisposable where T : BaseSingletonInstance<T>, new()
    {
        private static T _instance = null;
        private static object _locker = new object();

        public bool IsInitialize { get; set; }
        public virtual void Initialize()
        {
            this.IsInitialize = true;
        }

        public static T Instance
        {
            get
            {
                lock (_locker)
                {
                    if (_instance == null)
                    {
                        _instance = new T();
                    }
                    if (_instance.IsInitialize != true)
                    {
                        _instance.Initialize();
                    }
                }
                return _instance;
            }
        }
        public virtual void Dispose()
        {
            BaseSingletonInstance<T>._instance = null;
            System.GC.Collect();
        }
    }
}
